package 狂神多线程;
//线程礼让
//礼让不一定成功看cpu心情
public class TestYield {
    public static void main(String[] args) {
        myYield myYield = new myYield();
        Thread thread1 = new Thread(myYield,"a");
        Thread thread2 = new Thread(myYield, "b");
        thread1.start();
        thread2.start();

    }
}


class myYield implements Runnable{

    @Override
    public void run() {
        System.out.println("线程开始执行!"+Thread.currentThread().getName());
        Thread.yield(); //礼让
        System.out.println("线程停止执行!"+Thread.currentThread().getName());
    }
}